//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "adminActions\fn_ui_moderation_teleportme.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_isAdmin","_dialog","_player","_selected_index"];
PARAMS_2(_selected_index,_player);
if (GVAR(AdminCmds) == 1) then { 
	if (isnil "_player" || {isnull _player}) exitWith { hint localize "STR_MSO_AA_NOSELECTION"; };
	_isAdmin = (call mso_fnc_isAdmin);
	if (!isnil "mp_rights_fnc_isAdmin") then {
		_isAdmin = _isAdmin || ([] call mp_rights_fnc_isAdmin) || ([] call mp_rights_fnc_isModerator);
	};
	if (_isAdmin) then {
		GVAR(ui_moderation_confirm) = [false,"teleport",_player, getPlayerUID _player, name _player];
		if (vehicle _player != _player && {(driver (vehicle _player)) == _player}) then {
			_dialog = createDialog QGVAR(ui_moderation_confirm);
			waituntil {dialog};
			ctrlSetText [1, format["%1",GVAR(ui_moderation_confirm)]];
			waituntil {!dialog || !alive player};
			TRACE_1("confirm closed",GVAR(ui_moderation_confirm));
		} else {
			GVAR(ui_moderation_confirm) set [0, true];
		};
		TRACE_1("Confirmation",GVAR(ui_moderation_confirm));
		if (!isnil QGVAR(ui_moderation_confirm)
			&& {typename GVAR(ui_moderation_confirm) == typename []}
			&& {count GVAR(ui_moderation_confirm) > 0}) then {
			if (GVAR(ui_moderation_confirm) select 0) then {
				[QGVAR(TELEPORTTOME),[GVAR(ui_moderation_confirm),name player,getPlayerUID player],"all"] call FUNC(raiseEvent);
			};
		} else {
			TRACE_1("failed confirm",GVAR(ui_moderation_confirm));
		};
	}else {
		hint localize "STR_MSO_AA_CMD_NA";
	};
};

TRACE("End");
TMFPROFILERSTOP;
